﻿using System;
using System.BLL;
using System.Collections.Generic;
using System.Dto;
using System.IBLL;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace System.MVC.Controllers
{
    public class InteractionController : Controller
    {
        /// <summary>
        /// 留言查看页面
        /// </summary>
        /// <returns></returns>
        public ActionResult MessageList()
        {
            IInteractionManager manager = new InteractionManager();
            var data = manager.getAllMessageBoardLists();
            ViewBag.data = data;
            return View();
        }

        public ActionResult AddMessage()
        {
            return View();
        }

        [HttpPost]
        public JsonResult AddMessage(GetAllMessageBoardList dto)
        {
            IInteractionManager manager = new InteractionManager();
            dto.messageName = Session["userid"].ToString();
            manager.AddOneMessageByDto(dto);
            return Json(new { code = 0, msg = "留言成功" });
        }

        public ActionResult RegistrationActivity(int id)
        {
            ViewBag.id = id;
            return View();
        }

        [HttpPost]
        public JsonResult RegistrationActivity(ActivityRegistrationDto dto)
        {
            IInteractionManager manager = new InteractionManager();
            dto.userId = Session["userid"].ToString();
            dto.userName = Session["UserName"].ToString();
            manager.AddOneRegistrationActivityByDto(dto);
            return Json(new { code = 0, msg = "报名成功" });
        }

        /// <summary>
        /// 活动管理页面
        /// </summary>
        /// <returns></returns>
        public ActionResult ActivityList()
        {
            ViewBag.userPer = Session["DepartMentId"].ToString();

            return View();
        }

        public JsonResult GetActivityRelease1(int limit, int page, string activityName, string activityContent)
        {
            IInteractionManager manager = new InteractionManager();
            int datalet;
            var data = manager.getActivityReleaseLists(limit, page, out datalet, activityName, activityContent, "");
            data = data.Where(m => m.isPublish == "True").ToList();
            datalet = data.Count();
            return Json(new { code = 0, msg = "获取成功", count = datalet, data = data }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 活动管理页面table数据请求接口
        /// </summary>
        /// <param name="limit">条数</param>
        /// <param name="page">页数</param>
        /// <param name="activityName">活动名筛选</param>
        /// <param name="activityContent">活动内容筛选</param>
        /// <param name="isPublish">是否发布筛选</param>
        /// <returns></returns>
        public JsonResult GetActivityRelease(int limit, int page, string activityName, string activityContent, string isPublish)
        {
            IInteractionManager manager = new InteractionManager();
            int datalet;
            var data = manager.getActivityReleaseLists(limit, page, out datalet, activityName, activityContent, isPublish);
            return Json(new { code = 0, msg = "获取成功", count = datalet, data = data }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 活动管理页面table表发布按钮业务请求接口
        /// </summary>
        /// <param name="id">活动ID</param>
        /// <returns></returns>
        public JsonResult ReleaseActivity(int id)
        {
            IInteractionManager manager = new InteractionManager();
            manager.ReleaseActivityById(id);
            return Json(new { code = 0, msg = "操作成功" }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 活动添加页面
        /// </summary>
        /// <returns></returns>
        public ActionResult AddActivity()
        {
            return View();
        }
        /// <summary>
        /// 活动添加页面业务请求接口
        /// </summary>
        /// <param name="listDto">数据模型</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddActivity(GetActivityReleaseListDto listDto)
        {
            IInteractionManager manager = new InteractionManager();
            manager.AddOneActivityRewardByDto(listDto);
            return Json(new { code = 0, msg = "添加成功" });
        }
        /// <summary>
        /// 活动管理页面table删除按钮业务请求接口
        /// </summary>
        /// <param name="id">活动ID</param>
        /// <returns></returns>
        public JsonResult DelActivity(int id)
        {
            IInteractionManager manager = new InteractionManager();
            manager.DelOneActivityRewardById(id);
            return Json(new { code = 0, msg = "删除成功" }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 活动修改页面
        /// </summary>
        /// <param name="id">活动ID</param>
        /// <returns></returns>
        public ActionResult EditActivity(int id)
        {
            IInteractionManager manager = new InteractionManager();
            var data = manager.GetOneActivityRewardById(id);
            return View(data);
        }
        /// <summary>
        /// 活动修改页面业务请求接口
        /// </summary>
        /// <param name="listDto">数据模型</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult EditActivity(GetActivityReleaseListDto listDto)
        {
            IInteractionManager manager = new InteractionManager();
            manager.EditOneActivityRewardByDto(listDto);
            return Json(new { code = 0, msg = "修改成功" });
        }
        /// <summary>
        /// 在线调查页面
        /// </summary>
        /// <returns></returns>
        public ActionResult OnlineSurveyList()
        {
            ViewBag.userPer = Session["DepartMentId"].ToString();

            return View();
        }
        /// <summary>
        /// 在线调查页面table数据请求接口
        /// </summary>
        /// <param name="limit">条数</param>
        /// <param name="page">页数</param>
        /// <param name="surveyTitle">调查标题筛选</param>
        /// <param name="surveyContent">调查内容筛选</param>
        /// <param name="isPublish">是否发布筛选</param>
        /// <returns></returns>
        public JsonResult GetOnlineSurvey(int limit, int page, string surveyTitle, string surveyContent, string isPublish)
        {
            IInteractionManager manager = new InteractionManager();
            int datalet;
            var data = manager.getOnlineSurveyListDtos(limit, page, out datalet, surveyTitle, surveyContent, isPublish);
            return Json(new { code = 0, msg = "获取成功", count = datalet, data = data }, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetOnlineSurveyByPublish(int limit, int page, string surveyTitle, string surveyContent)
        {
            IInteractionManager manager = new InteractionManager();
            int datalet;
            var data = manager.getOnlineSurveyListDtos(limit, page, out datalet, surveyTitle, surveyContent, "True");
            return Json(new { code = 0, msg = "获取成功", count = datalet, data = data }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 在线调查页面table发布按钮业务请求接口
        /// </summary>
        /// <param name="id">调查信息ID</param>
        /// <returns></returns>
        public JsonResult ReleaseOnlineSurvey(int id)
        {
            IInteractionManager manager = new InteractionManager();
            manager.ReleaseOnlineSurveyById(id);
            return Json(new { code = 0, msg = "操作成功" });
        }
        /// <summary>
        /// 在线调查页面table删除按钮业务请求接口
        /// </summary>
        /// <param name="id">调查信息ID</param>
        /// <returns></returns>
        public JsonResult DelOnlineSurvey(int id)
        {
            IInteractionManager manager = new InteractionManager();
            manager.DelOneOnlineSurveyById(id);
            return Json(new { code = 0, msg = "删除成功" }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 添加调查信息页面
        /// </summary>
        /// <returns></returns>
        public ActionResult AddOnlineSurvey()
        {
            return View();
        }
        /// <summary>
        /// 添加调查信息页面业务请求接口
        /// </summary>
        /// <param name="listDto">数据模型</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddOnlineSurvey(GetOnlineSurveyListDto listDto)
        {
            IInteractionManager manager = new InteractionManager();
            manager.AddOneOnlineSurveyByDto(listDto);
            return Json(new { code = 0, msg = "添加成功" });
        }
        /// <summary>
        /// 在线调查信息修改页面
        /// </summary>
        /// <param name="id">调查信息ID</param>
        /// <returns></returns>
        public ActionResult EditOnlineSurvey(int id)
        {
            IInteractionManager manager = new InteractionManager();
            var data = manager.GetOneOnlineSurveyById(id);
            return View(data);
        }
        /// <summary>
        /// 在线调查信息修改页面业务请求接口
        /// </summary>
        /// <param name="listDto">数据模型</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult EditOnlineSurvey(GetOnlineSurveyListDto listDto)
        {
            IInteractionManager manager = new InteractionManager();
            manager.EditOneOnlineSurveyByDto(listDto);
            return Json(new { code = 0, msg = "修改成功" });
        }


        public ActionResult CheckOnePublicity(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public JsonResult GetAllActivitySignList(int id,int limit, int page, string userName)
        {

            IInteractionManager manager = new InteractionManager();
            int datalet;
            var data = manager.GetActivityRegistrationById(id,limit, page, out datalet, userName);
            return Json(new { code = 0, msg = "获取成功", count = datalet, data = data }, JsonRequestBehavior.AllowGet);

        }

    }
}